package cn.wolfcode.wms.web.controller;

import cn.wolfcode.wms.domain.Brand;
import cn.wolfcode.wms.qo.QueryObject;
import cn.wolfcode.wms.service.IBrandService;
import cn.wolfcode.wms.util.JSONResult;
import cn.wolfcode.wms.util.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("brand")
public class BrandController {
    @Autowired
    private IBrandService brandService;
    @RequestMapping("list")
    public String list(Model model, @ModelAttribute("qo") QueryObject qo){

        PageResult result = brandService.queryForList(qo);

        model.addAttribute("result",result);
        return "brand/list";
    }

    @RequestMapping("input")
    public String input(Model model,Long id){
        if (id != null) {
            Brand entity = brandService.get(id);
            model.addAttribute("entity",entity);
        }
        return "brand/input";
    }
    @RequestMapping("saveOrUpdate")
    @ResponseBody
    public Object saveOrUpdate(Brand entity){
       brandService.saveOrUpdate(entity);
        return new JSONResult();
    }
    @ResponseBody
    @RequestMapping("delete")
    public Object delete(Long id){

       brandService.delete(id);
        JSONResult json = new JSONResult();
        return json;
    }
}
